package com.example.wly.middletestapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Activity_1767111204 extends AppCompatActivity {

    int sum = 0;
    int add = 0;
    int result = 0;
    TextView tvResult;
    EditText etSum;
    EditText etAdd;
    Button btnAdd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_1767111204);


        tvResult = (TextView)  findViewById(R.id.tv_result);
        etSum = (EditText) findViewById(R.id.et_sum);
        etAdd = (EditText) findViewById(R.id.et_add);
        btnAdd = (Button) findViewById(R.id.btn_add);

        etSum.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                //改变完之后，处理代码
                //当文本输入框，输入完数据，获取每个输入框的数值
                String sumString = etSum.getText().toString();//'100'
                if(sumString.equals("")) {
                    sum = 0;
                }else{
                    sum = Integer.parseInt(sumString);//将字符串转换成整形数
                }
                //根据数值合成color值，设置到Imageview
                //tvResult.setText(sum+add);
            }
        });

        etAdd.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                //改变完之后，处理代码
                //当文本输入框，输入完数据，获取每个输入框的数值
                String addString = etAdd.getText().toString();//'100'
                if(addString.equals("")) {
                    add = 0;
                }else{
                    add = Integer.parseInt(addString);//将字符串转换成整形数
                }

            }
        });

        btnAdd.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                tvResult.setText(sum+add+"");
            }
        });

    }
}
